export const random_all = async function(imgMaxheight, imgMinheight, imgWidth) {
    let pageSize = 8;
    let random_list = [];
    for (let j = 0; j < pageSize; j++) {
        let _height = Math.floor(Math.random() * (imgMaxheight - imgMinheight) + imgMinheight);
        let loveNum = Math.floor(Math.random() * 10000);
        let id = Math.floor(Math.random() * 10000);
        let word = getRandomChineseWord(16);
        let _color = getRandomColor();
        random_list.push({
            id,
            height: _height,
            src: `https://via.placeholder.com/${imgWidth}X${_height}/${_color}/?text=Hello+World`,
            loveNum,
            word
        })
    }

    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(random_list);
            // reject(random_list);
        }, 500);
    })
}

function getRandomChineseWord(size) {
    let res = "";
    let _rsl = "";
    for (let i = 0; i < size; i++) {
        let _randomUniCode = Math.floor(Math.random() * (40870 - 19968) + 19968).toString(16);
        eval("_rsl=" + '"\\u' + _randomUniCode + '"');
        res += _rsl;
        _rsl = "";
    }
    return res

}

function getRandomColor() {
    let str = "";
    let arr = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
    for (let i = 0; i < 6; i++) {
        let num = parseInt(Math.random() * 16);
        str += arr[num];
    }
    return str;
}